package com.newjiabo.web.controller.system;

import com.newjiabo.common.annotation.Log;
import com.newjiabo.common.core.controller.BaseController;
import com.newjiabo.common.core.domain.AjaxResult;
import com.newjiabo.common.enums.BusinessType;
import com.newjiabo.system.domain.SysRegion;
import com.newjiabo.system.service.ISysRegionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.swing.plaf.synth.Region;
import javax.validation.Valid;
import java.util.List;

/**
 * {类内容}
 *
 * @author CaoMengHui.
 * @version 1.0
 * @since 2023/9/18 14:32
 */
@RestController
@Api(tags = "后台;行政管理")
@RequestMapping("/system/setting/region")
public class SysRegionController extends BaseController {
    @Resource
    private ISysRegionService regionService;

    @PostMapping(value = "/sync")
    @ApiOperation(value = "同步高德行政地区数据")
    public void synchronizationData() {

    }

    @GetMapping("/{id}")
    @ApiOperation(value = "通过id获取详情")
    public AjaxResult get(@PathVariable String id) {
        return AjaxResult.success(regionService.selectSysRegionById(id));
    }

    @GetMapping("/item/{id}")
    @ApiOperation(value = "通过id获取子地区")
    public AjaxResult getItem(@PathVariable String id) {
        return AjaxResult.success(regionService.getItem(id));
    }

    @PostMapping
    @ApiOperation(value = "新增行政地区")
    public AjaxResult save(SysRegion region) {
        return AjaxResult.success(regionService.insertSysRegion(region));
    }

    @PutMapping(value = "/{id}")
    @ApiImplicitParam(name = "id", value = "地区ID", required = true, dataType = "String", paramType = "path")
    @ApiOperation(value = "更新地区")
    public AjaxResult update(@PathVariable String id, @Valid SysRegion region) {
        regionService.updateSysRegion(region);
        return AjaxResult.success(region);
    }

    /**
     * 删除行政地区
     */
    @PreAuthorize("@ss.hasPermi('system:region:remove')")
    @Log(title = "行政地区", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(regionService.deleteSysRegionByIds(ids));
    }
}
